org.piratis.j2me.core.game
Class Canvas

java.lang.Object
  extended byjavax.microedition.lcdui.Canvas
      extended byorg.piratis.j2me.core.game.Canvas
All Implemented Interfaces:
java.lang.Runnable

public class Canvas
extends javax.microedition.lcdui.Canvas
implements java.lang.Runnable

CoreCanvas Description

Version:
$Id: Canvas.java,v 1.3 2004/07/22 16:49:42 piratis Exp $
Author:
Jordi Martín
See Also:
Serialized Form

Field Summary
protected  Display display
          Canvas display
protected  Image offscreen
          Double buffering image
 
Constructor Summary
Canvas(Display display)
          Creates a new instance of a CoreCanvas, with an empty (white pixels) buffer for offscreen processing.
 
Method Summary
 void flushGraphics()
          Flushes the off-screen buffer to the display.
 Display getDisplay()
           
protected  Graphics getGraphics()
          Returns the Graphics object for rendering a Game Canvas: it will be the Graphics object of the off-screen buffer.
protected  void keyPressed(int keyCode)
           
protected  void keyReleased(int keyCode)
           
protected  void paint(Graphics g)
           
protected  void paintBackground(Graphics g, BBox2D area)
          Paints the current background (if any).
 void run()
          To be called by a Display#callSerially(java.lang.Runnable) when requesting a new repaint.
protected  void setEngine(Engine newEngine)
          Sets its associated engine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

display

protected Display display
Canvas display


offscreen

protected Image offscreen
Double buffering image

Constructor Detail

Canvas

public Canvas(Display display)
Creates a new instance of a CoreCanvas, with an empty (white pixels) buffer for offscreen processing.

Parameters:
display - Canva's display
Method Detail

getGraphics

protected Graphics getGraphics()
Returns the Graphics object for rendering a Game Canvas: it will be the Graphics object of the off-screen buffer.

Painting operations will not be visible on the display as long as flushGraphics() is not called

Returns:
this off-screen's Graphic object

getDisplay

public Display getDisplay()
Returns:
the canvas' display

run

public void run()
To be called by a Display#callSerially(java.lang.Runnable) when requesting a new repaint. It is the same as calling flushGraphics().

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run(), flushGraphics(), Display#callSerially(java.lang.Runnable)

paint

protected void paint(Graphics g)
See Also:
javax.microedition.lcdui.Displayable#paint(Graphics)

paintBackground

protected void paintBackground(Graphics g,
                               BBox2D area)
Paints the current background (if any). Default implementation clears the background with bgColor

Parameters:
g - graphics context
area - dirty region

setEngine

protected void setEngine(Engine newEngine)
Sets its associated engine. High coupling between Canvas and Engine!

Parameters:
newEngine - its engine
See Also:
Engine

flushGraphics

public void flushGraphics()
Flushes the off-screen buffer to the display.


keyPressed

protected void keyPressed(int keyCode)

keyReleased

protected void keyReleased(int keyCode)

Copyright(c) 2003-2004 Jordi Martin